/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Connection.DataAccess;
import Model.DienThoai;

/**
 *
 * @author My PC
 */
public class DienThoaiController {
     public static boolean ThemDT(DienThoai dt)
    {
        try 
        {
            
           String sql = "INSERT INTO tblSanPham (MA_SANPHAM, "
                   + "TEN_SANPHAM, MOTA,DONGIA, SOLUONG,"
            + "MA_CHUNGLOAI, MA_NHACUNGCAP, BAOHANH) "
                   + "values (N'"+dt.getMaSanpham()+"',N'"+dt.getTenSanpham()+"',N'"+dt.getMota()+"',"
                   + ""+dt.getDongia()+","+dt.getSoluong()+","
                   + "N'"+dt.getMaChungloai()+"',N'"+dt.getMaNCC()+"',"
                   + "N'"+dt.getBaohanh()+"')";
           DataAccess da=new DataAccess();
           da.executeUpdate(sql);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
     public static boolean XoaDT(DienThoai dt)
    {
        try 
        {
            
           String sql = "delete from tblSanPham where MA_SANPHAM =N'"+dt.getMaSanpham()+"'";
           DataAccess da=new DataAccess();
           da.executeUpdate(sql);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
     public static boolean SuaDT(DienThoai dt)
    {
        try 
        {
            
           String sql = "UPDATE tblSanPham SET TEN_SANPHAM = "
                   + "N'"+dt.getTenSanpham()+"',"
                   + "MOTA = N'"+dt.getMota()+"',DONGIA= "+dt.getDongia()+" ,"
                   + "SOLUONG = "+dt.getSoluong()+","
                   + "MA_CHUNGLOAI = N'"+dt.getMaChungloai()+"',"
                   + "MA_NHACUNGCAP = N'"+dt.getMaNCC()+"',"
                  +" BAOHANH = N'"+dt.getBaohanh()+"'"
                   + "WHERE MA_SANPHAM = N'"+dt.getMaSanpham()+"'";
           DataAccess da=new DataAccess();
           da.executeUpdate(sql);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
    
}
